package club.emergency.wechat.question.operate.consumer.service.fallback_factory;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.model.question.Question;
import club.emergency.wechat.model.question.QuestionDailyRecord;
import club.emergency.wechat.question.operate.consumer.service.QuestionOperateConsumer;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.question.operate.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class QuestionOperateFallbackFactory implements FallbackFactory<QuestionOperateConsumer> {
    @Override
    public QuestionOperateConsumer create(Throwable throwable) {
        return new QuestionOperateConsumer() {
            @Override
            public String save(Question question, String choiceOptionList) {
                return ResponseEntity.error(StatusCode.DB_SAVE_ERROR, "新增题目数据失败！", throwable.getMessage());
            }

            @Override
            public String saveFromExcel(String suffix, byte[] bytes) {
                return ResponseEntity.error(StatusCode.DB_SAVE_ERROR, "从excel中导入试题失败！", throwable.getMessage());
            }

            @Override
            public String modify(Question question, String choiceOptionList) {
                return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "修改题目数据失败！", throwable.getMessage());
            }

            @Override
            public String remove(Long id, String choiceOptionIdList) {
                return ResponseEntity.error(StatusCode.DB_REMOVE_ERROR, "删除题目数据失败！", throwable.getMessage());
            }

            @Override
            public String checkCorrectForDaily(QuestionDailyRecord questionDailyRecord, String userOption) {
                return ResponseEntity.error(StatusCode.CHECK_ERROR, "判断日常答题失败！", throwable.getMessage());
            }
        };
    }
}
